//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.imagemanager.util;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.MediaStore.Images.Media;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {
    private static final String TAG = "BootReceiver";
    private final Handler mHandler = new Handler();
    private boolean mListenersInitialized = false;

    public BootReceiver() {
    }

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.i("BootReceiver", "Got intent with action " + action);
        if("android.intent.action.MEDIA_SCANNER_FINISHED".equals(action)) {
            CacheService.markDirty(context);
            CacheService.startCache(context, true);
        } else if("android.intent.action.MEDIA_MOUNTED".equals(action)) {
            if(!this.mListenersInitialized) {
                this.mListenersInitialized = true;
                Handler handler = this.mHandler;
                ContentObserver localObserver = new ContentObserver(handler) {
                };
                Uri uriImages = Media.EXTERNAL_CONTENT_URI;
                Uri uriVideos = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                ContentResolver cr = context.getContentResolver();
                cr.registerContentObserver(uriImages, false, localObserver);
                cr.registerContentObserver(uriVideos, false, localObserver);
            }
        } else if(action.equals("android.intent.action.MEDIA_EJECT")) {
            CacheService.sAlbumCache.close();
            CacheService.sMetaAlbumCache.close();
            CacheService.sSkipThumbnailIds.flush();
        }

    }
}
